﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BLToolkit.DataAccess;
using System.IO;
using BLToolkit.Validation;

namespace Clipping.Utils.Repositories
{
    [TableName(Name = "News")]
    public class NEWS : ModelBase<NEWS>
    {

        class NEWSUpdater : DBPartUpdater<NEWSUpdater>
        {
            static NEWSUpdater()
            {
                Actions[typeof(NEWSUpdater)] = new List<UpdateAction>();

                #region 数据库升级脚本

                Versions[typeof(NEWSUpdater)] = 0;

                #region 创建表 Keywords

                AddUpdateAction(typeof(NEWSUpdater), @"CREATE TABLE News(
Url VARCHAR2(1000) NOT NULL,
Title VARCHAR2(1000) NOT NULL,
Date VARCHAR2(100),
Media VARCHAR2(200),
TextContent VARCHAR2(20000),
HtmlContent VARCHAR2(20000),
);      
");
                #endregion

                #endregion
            }
        }

        static NEWS()
        {
            string dbPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DB", "News.db");
            var connPool = DBHelper.CreateDBConnectionPool<NewsDBUpdater>(dbPath, 10);
            DBHelper.UpdateTableSchema<NEWSUpdater>(connPool);
        }

        [PrimaryKey(0), Required]
        public string Url { get; set; }


        [Required]
        public string Title { get; set; }


        public string Date { get; set; }

        public string Media { get; set; }


        public string TextContent { get; set; }


        public string HtmlContent { get; set; }
    }
    public class NewsDBUpdater : DBUpdater
    {
        /// <summary>
        /// 升级脚本初始化
        /// 所有的数据库操作语句都集中在这里，方便数据库自动升级
        /// </summary>
        static NewsDBUpdater()
        {
            Actions[typeof(NewsDBUpdater)] = new List<UpdateAction>();

            #region 数据库升级脚本

            Versions[typeof(NewsDBUpdater)] = 0;

            #endregion
        }
    }

}
